/**
 * Created by 余保林 on 2017/8/9.
 */
import ajax from '../ajax'
const menu = [
  {
    id: 1,
    title: '首页',
    icon: 'gear-b',
    sort: 6,
    url: '/home',
    children: []
  },
  {
    id: 2,
    title: '系统配置',
    icon: 'gear-b',
    sort: 7,
    url: '/system',
    children: [
      {
        id: 3,
        title: '用户管理',
        icon: 'gear-b',
        sort: 9,
        url: '/system/user',
        children: []
      },
      {
        id: 4,
        title: '角色管理',
        icon: 'gear-b',
        sort: 10,
        url: '/system/role',
        children: []
      },
      {
        id: 5,
        title: '菜单管理',
        icon: 'gear-b',
        sort: 11,
        url: '/system/menu',
        children: []
      },
      {
        id: 6,
        title: '权限管理',
        icon: 'gear-b',
        sort: 12,
        url: '/system/auth',
        children: [
          {
            id: 89,
            title: '菜单权限',
            icon: 'gear-b',
            sort: 12,
            url: '/system/auth',
            children: []
          },
          {
            id: 79,
            title: '接口权限',
            icon: 'gear-b',
            sort: 12,
            url: '/system/auxxxth',
            children: []
          }
        ]
      }
    ]
  }
]

export default {
  getMenu (cb) {
    setTimeout(() => cb(menu), 1000)
  },
  getMenuTree (success, fail = null) {
    ajax.get({
      url: `/api/menu/menuTree`,
      success,
      fail
    })
  },
  getRoleMenu (roleId, success, fail = null) {
    ajax.get({url: `/api/menu/roleMenu?roleId=${roleId}`, success, fail})
  },
  saveMenu (menuData, success, fail = null) {
    const method = menuData.id === 0 ? 'post' : 'put'
    ajax[method]({url: `/api/menu/${menuData.id}`, data: menuData, success, fail})
  },
  deleteMenus (menuIds, success) {
    ajax.del({url: `/api/menu/deleteList`, data: {ids: menuIds}, success})
  }
}
